#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version        : 1.0
# @Create Time    : 2024/9/6 11:11
# @File           : feature
# @IDE            : PyCharm
# @desc           : 描述
from datetime import datetime
from typing import List

from sqlalchemy.orm import Mapped, mapped_column, relationship
from db.db_base import BaseModel, AuditModel
from sqlalchemy import JSON, String, DateTime, ForeignKey, Integer, Text, Boolean, UniqueConstraint


class DCQARFemale(AuditModel):
    __tablename__ = "dc_check_qar_female"
    __table_args__ = (
        {'comment': 'QAR母本主表'}
    )
    
    version: Mapped[int] = mapped_column(Integer, comment="版本", default=1)
    status: Mapped[str] = mapped_column(String(20), comment="状态", default="创建中")

    part_no: Mapped[str] = mapped_column(String(40), index=True, comment="材料/图号，零件件号")
    part_type: Mapped[str] = mapped_column(String(20), nullable=True, comment="零件/材料类型，由物料类型对应获取")

    part_name: Mapped[str] = mapped_column(String(40), comment="材料/零件名称")
    material_no: Mapped[str] = mapped_column(Text, comment="物料编号, 同一件号会有多个物料号，用;分割")

    ######################### 物料主数据带入字段 #############################################
    rev_letter: Mapped[str] = mapped_column(String(20), nullable=True, comment="更改字母")
    temper: Mapped[str] = mapped_column(String(20), nullable=True, comment="状态")
    zpm_cpm: Mapped[str] = mapped_column(String(20), nullable=True, comment="工艺材料编号")
    typing: Mapped[str] = mapped_column(String(20), nullable=True, comment="型别")
    classing: Mapped[str] = mapped_column(String(20), nullable=True, comment="类别/组合物别")
    grade: Mapped[str] = mapped_column(String(20), nullable=True, comment="级别")
    form: Mapped[str] = mapped_column(String(20), nullable=True, comment="形式/形态")
    size: Mapped[str] = mapped_column(String(20), nullable=True, comment="规格")
    color: Mapped[str] = mapped_column(String(20), nullable=True, comment="色号")
    
    material_type: Mapped[str] = mapped_column(String(20), nullable=True, comment="物料类型：结构件")
    ###########################################################################################

    ########################## 质量计划人员填写字段 #############################################
    product_type: Mapped[str] = mapped_column(String(20), nullable=True, comment="产品型号(机型)")
    spec_stan: Mapped[str] = mapped_column(String(20), nullable=True, comment="规范/标准")
    spec_stan_rev: Mapped[str] = mapped_column(String(20), nullable=True, comment="规范/标准版次")
    
    mat_code: Mapped[str] = mapped_column(String(20), nullable=True, comment="MAT号或工程文件")
    test_items: Mapped[str] = mapped_column(String(20), nullable=True, comment="试验项数")
    required_dimension: Mapped[str] = mapped_column(String(40), nullable=True, comment="要求尺寸")
    pclr_quantity: Mapped[str] = mapped_column(String(20), nullable=True, comment="试样数量")
    pclr_size: Mapped[str] = mapped_column(String(20), nullable=True, comment="试样规格/尺寸")

    plan_remark: Mapped[str] = mapped_column(String(100), nullable=True, comment="计划备注")
    life_limit_req: Mapped[str] = mapped_column(String(20), nullable=True, comment="限寿工程要求")
    life_limit_date: Mapped[datetime] = mapped_column(DateTime, nullable=True, comment="限寿基准日期")
    life_limit_period: Mapped[str] = mapped_column(String(20), nullable=True, comment="限寿库房存储期限")
    life_limit_manage: Mapped[str] = mapped_column(String(20), nullable=True, comment="限寿管控方式")

    is_sampling: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否抽样, 勾选")
    
    ########################## 质量计划人员填写, 机载系统零件需求字段，SAMC 05-115.3 ###############################
    special_property: Mapped[str] = mapped_column(String(20), nullable=True, comment="性能要求")
    manufacturer: Mapped[str] = mapped_column(String(20), nullable=True, comment="制造商")
    change_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="更改号或其他补充标识")
    draw_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="图号")
    draw_no_rev: Mapped[str] = mapped_column(String(20), nullable=True, comment="图号版次")
    software_code: Mapped[str] = mapped_column(String(20), nullable=True, comment="软件件号")
    software_rev: Mapped[str] = mapped_column(String(20), nullable=True, comment="软件版本")
    atp_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="ATP编号")
    ###########################################################################################

    is_insp: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否检验，填写检验项目后自动判断")
    is_test: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否试验，填写试验项目后自动判断")
    is_life_limit: Mapped[bool] = mapped_column(Boolean, nullable=True, comment="是否限寿件，系统查询限寿件数据自动判断")
    is_correct_order: Mapped[bool] = mapped_column(Boolean, default=False, comment="是否有纠正委托，系统查询纠正委托信息进行判断")

    remark: Mapped[str] = mapped_column(String(100), nullable=True, comment="备注")

    # contents: Mapped[List["DCQARFemaleContent"]] = relationship(back_populates="qar_female")
    contents: Mapped[List[dict]] = mapped_column(JSON, nullable=True, default=[], comment="检验内容")
    asr_features: Mapped[List[dict]] = mapped_column(JSON, nullable=True, default=[], comment="ASR特征")


# class DCQARFemaleContent(AuditModel):
#     __tablename__ = "dc_check_qar_female_content"
#     __table_args__ = ({'comment': 'QAR母本检验内容表'})

#     qar_female_id: Mapped[int] = mapped_column(
#         Integer,
#         ForeignKey("dc_check_qar_female.id", ondelete='CASCADE'),
#         comment="QAR母本ID"
#     )
#     qar_female: Mapped[DCQARFemale] = relationship(foreign_keys=qar_female_id, back_populates='contents')

#     content_type: Mapped[str] = mapped_column(String(20), comment="类型，检验项目、试验要求、限制要求等")
#     project: Mapped[str] = mapped_column(String(40), comment="项目，定义不同类型中项目信息，如检验项目中的标识、证书等")
#     detail: Mapped[str] = mapped_column(String(60), nullable=True, comment="项目明细")
#     attachment: Mapped[str] = mapped_column(Text, nullable=True, comment="附件")
#     remark: Mapped[str] = mapped_column(Text, nullable=True, comment="备注")


# class DCQARFemaleASRFeature(AuditModel):
#     __tablename__ = "dc_check_qar_female_asr_feature"
#     __table_args__ = ({'comment': 'QAR母本ASR特征子表'})

#     qar_female_id: Mapped[int] = mapped_column(
#         Integer,
#         ForeignKey("dc_check_qar_female.id", ondelete='CASCADE'),
#         comment="QAR母本ID"
#     )
#     qar_female: Mapped[DCQARFemale] = relationship(foreign_keys=qar_female_id, back_populates='asr_features')

#     part_no: Mapped[str] = mapped_column(String(40), comment="材料/零件图号")
#     characteristic: Mapped[str] = mapped_column(String(40), comment="特征")
#     dimension: Mapped[str] = mapped_column(String(40), comment="尺寸")

#     irr: Mapped[str] = mapped_column(String(10), nullable=True, comment="初始可靠值")
#     grade: Mapped[str] = mapped_column(String(10), nullable=True, comment="等级")
#     count: Mapped[str] = mapped_column(String(20), nullable=True, comment="特征计数")
